﻿package com.wandian.view.components.ui
{   
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.vo.PlayerVo;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;

	/**   
	 * 一套玩家操作信息组件
	 * @author long
	 * @Create  2012-10-22 下午03:12:00   
	 * @QQ 108232706
	 * @version 1.0   
	 */   
    public class Player extends Object
    {
        private var _nSeatId:int = 0;
        /**
         * [level_mc:星级，txt_name：昵称]
         * @default 
         */
        private var _mcInfo:MovieClip;
        private var _mcFL:MovieClip;
        private var _mcTime:MovieClip;
        private var _mcOperate:MovieClip;
        private var _timer:TimerManage;
        private var _mcPic:Sprite;
        private var _mcWin:MovieClip;
        private var _facade:ApplicationFacade;
        private var _levelManage:LevelManage;
        private var _global:GameData;
        /**
         * [1-5]
         * @default 
         */
        private var _mcVip:MovieClip;

        public function Player(seatId:int, mcInfo:MovieClip, mcFL:MovieClip, mcTime:MovieClip, mcOperate:MovieClip, mcWin:MovieClip)
        {
            this._facade = ApplicationFacade.getInstance();
            this._global = GameData.getInstance();
            this._nSeatId = seatId;
            this._mcInfo = mcInfo;
            this._mcWin = mcWin;
            this._mcWin.gotoAndStop(1);
            this._mcWin.mouseChildren = false;
            this._mcFL = mcFL;
            this._mcFL.gotoAndStop(1);
            this._mcFL.visible = false;
            this._mcTime = mcTime;
            this._mcOperate = mcOperate;
            this._levelManage = new LevelManage();
            this._timer = new TimerManage(this._mcFL, this._mcTime);
            this._mcVip = GameData.getMovieClip("VIP");
            this._mcInfo.addChild(this._mcVip);
            this._mcVip.x = -2.25;
            this._mcVip.y = -0.75;
            this.initHideThis();
            return;
        }

        private function initHideThis() : void
        {
            this._mcOperate.mc_money.txt.selectable = false;
            this._mcOperate.mc_type.txt.selectable = false;
            this._mcOperate.mc_type.txt.text = "";
            this._mcOperate.mc_money.txt.text = "";
            this._mcOperate.mc_type.visible = false;
            this._mcOperate.mc_money.visible = false;
            this._mcInfo.visible = false;
            return;
        }

        public function sitDown(playerInfo:PlayerVo) : void
        {
            this._mcOperate.mc_type.visible = true;
            this._mcOperate.mc_money.visible = true;
            this._levelManage.updateLevel(this._mcInfo.level_mc, playerInfo.level);
            if (playerInfo.vip)
            {
                this._mcVip.gotoAndStop(playerInfo.vip);
                this._mcVip.visible = true;
            }
            else
            {
                this._mcVip.visible = false;
            }
            this._mcInfo.txt_name.text = playerInfo.name;
            if (playerInfo.sex == 0)
            {
                if (playerInfo.initSex == 1)
                {
                    this._mcInfo.txt_name.textColor = 16751103;
                }
                else
                {
                    this._mcInfo.txt_name.textColor = 16777215;
                }
            }
            else if (playerInfo.sex == 1)
            {
                this._mcInfo.txt_name.textColor = 16751103;
            }
            else
            {
                this._mcInfo.txt_name.textColor = 16777215;
            }
            this._mcInfo.visible = true;
            this.updateStake(playerInfo);
            return;
        }

        /**
         * 更新玩家总金额
         * @param playerInfo
         */
        public function updateStake(playerInfo:PlayerVo) : void
        {
            this._mcOperate.mc_money.txt.text = playerInfo.stake + playerInfo.giveChip + "";
            return;
        }

        /**
         * 更新玩家操作状态显示
         * @param playerInfo
         */
        public function updateLastAction(playerInfo:PlayerVo = null) : void
        {
            var lastAction:int = 0;
            var arrCardType:Array = null;
            var cardTypeIndex:int = 0;
            var msg:String = null;
            if (playerInfo == null)
            {
                lastAction = 0;
            }
            else
            {
                lastAction = playerInfo.lastAction;
            }
            if (lastAction == 0)
            {
                this._mcOperate.mc_type.txt.text = "";
                this._mcOperate.mc_type.visible = false;
            }
            else
            {
                this._mcOperate.mc_type.visible = true;             
                if (lastAction >= 10&&lastAction < 20)//显示获胜,高牌|一对|两对|三条|顺子。。
                {
                    cardTypeIndex = lastAction - 10;
                    arrCardType = GameData.tip["cardType"].split("|");
                    msg = "";
                    if (playerInfo.isWin == 1)
                    {
                        msg = GameData.tip["WIN"];
                    }
                    this._mcOperate.mc_type.txt.text = arrCardType[cardTypeIndex] + msg;
                }
                else if (lastAction < 10)//看牌|弃牌|跟注|加注|全押|小盲注|大盲注
                {
                    arrCardType = GameData.tip["OperateAction"].split("|");
                    this._mcOperate.mc_type.txt.text = arrCardType[(lastAction - 1)];
                }
                else if (lastAction == GameData.WAIT_NEXT_GAME)//等待下一局
                {
                    this._mcOperate.mc_type.txt.text = GameData.tip["WAITNEXTGAME"];
                    if (this._global.isStopGame)
                    {
						if (playerInfo.userid == this._global.userInfo.userVo.userid)
						{
							this._facade.sendNotification(CLZNoticeName.ONLINE_TIME_OUT_GAME);
						}
                    }
                
                }
                else if (lastAction == GameData.WAIT_BUY_IN)//等待买入
                {
                    this._mcOperate.mc_type.txt.text = GameData.tip["WAITBUYIN"];
                }
                else
                {
                    this._mcOperate.mc_type.visible = false;
                }
            }
            return;
        }

        public function playLevel(param1:int) : void
        {
            if (this._levelManage != null)
            {
                this._levelManage.playFlash(param1);
            }
            if (this._mcInfo.visible)
            {
            }
            if (this._global.userInfo.userVo.gp != GameData.QQSGAME_SID)
            {
                this._mcWin.gotoAndPlay(2);
            }
            return;
        }

        public function standUp(param1:Object) : void
        {
            this.initHideThis();
            this.hideTimer();
            this._mcVip.visible = false;
            this._mcWin.gotoAndStop(1);
            return;
        }

        public function showTimer(playerInfo:PlayerVo = null) : void
        {
            this.updateLastAction(playerInfo);
            this._timer.showTimer();
            return;
        }

        public function hideTimer(data:Object = null) : void
        {
            this._timer.hideTimer();
            return;
        }

        public function init(playerInfo:PlayerVo = null) : void
        {
            if (playerInfo == null)
            {
                this._mcOperate.mc_type.txt.text = "";
                this._mcOperate.mc_type.visible = false;
            }
            else
            {
                if (playerInfo.lastAction != 2)
                {
                }
                if (playerInfo.lastAction != 5)
                {
                }
                if (playerInfo.lastAction != GameData.WAIT_NEXT_GAME)
                {
                }
                if (playerInfo.lastAction != GameData.WAIT_BUY_IN)
                {
                    this._mcOperate.mc_type.txt.text = "";
                    this._mcOperate.mc_type.visible = false;
                }
            }
            this._timer.hideTimer();
            return;
        }

		public function hideNameInfo() : void
		{
			this._mcInfo.visible = false;
			return;
		}
		
		public function showNameInfo() : void
		{
			this._mcInfo.visible = true;
			return;
		}
		
        public function removeThis() : void
        {
            this._timer.removeThis();
            if (this._mcVip != null)
            {
            }
            if (this._mcInfo.contains(this._mcVip))
            {
                this._mcInfo.removeChild(this._mcVip);
                this._mcVip = null;
            }
            if (this._levelManage != null)
            {
                this._levelManage.removeLevel(this._mcInfo.level_mc);
                this._levelManage = null;
            }
            return;
        }

    }
}
